package com.ruoyi.api.controller;

import com.ruoyi.api.domain.Order;
import com.ruoyi.api.service.IOrderService;
import com.ruoyi.api.vo.OrderVo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单
 *
 * @author 寻觅
 * @since 2025-06-04
 */
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {
    @Autowired
    IOrderService iOrderService;

    /**
     * 创建订单
     */
    @PostMapping("createOrder")
    public AjaxResult createOrder(@RequestBody List<Integer> productIds, @RequestParam Integer userId) {
        return AjaxResult.success(iOrderService.createOrder(productIds, userId));
    }

    /**
     * 取消订单
     */
    @GetMapping("cancelOrder")
    public AjaxResult cancelOrder(@RequestParam String orderId) {
        return AjaxResult.success(iOrderService.cancelOrder(orderId));
    }

    /**
     * 支付订单
     */
    @GetMapping("payOrder")
    public AjaxResult payOrder(@RequestBody Order order) {
        return AjaxResult.success(iOrderService.payOrder(order));
    }

    /**
     * 查询订单详情
     */
    @GetMapping("info")
    public AjaxResult info(@RequestParam String orderId) {
        return AjaxResult.success(iOrderService.info(orderId));
    }

    /**
     * 查询订单列表
     */
    @PostMapping("list")
    public AjaxResult list() {
        return AjaxResult.success(iOrderService.listData());
    }

    /**
     * 修改订单地址和支付方式
     */
    @GetMapping("editAddress")
    public AjaxResult editAddress(@RequestParam String id, @RequestParam Integer addressId, @RequestParam Integer payType) {
        return AjaxResult.success(iOrderService.editAddress(id, addressId,payType));
    }
}
